}" | sh -e
}
+
+##
+# link_exists interface
+#
+# Returns 0 if the interface named exists (whether up or down), 1 otherwise.
+#
+link_exists()
+{
+ if ip link show "$1" >&/dev/null
+ then
+ return 0
+ else
+ return 1
+ fi
+}
+
+
# Usage: create_bridge bridge
create_bridge () {
local bridge=$1
return
fi
- if ! ip link show 2>/dev/null | grep -q "^[0-9]*: ${vdev}"; then
- echo "
+ if ! link_exists "$vdev"; then
+ if link_exists "$pdev"; then
+ # The device is already up.
+ return
+ else
+ echo "
Link $vdev is missing.
This may be because you have reached the limit of the number of interfaces
that the loopback driver supports. If the loopback driver is a module, you
driver is compiled statically into the kernel, then you may set the parameter
using loopback.nloopbacks=<N> on the domain 0 kernel command line.
" >&2
- exit 1
+ exit 1
+ fi
fi
create_bridge ${bridge}
- if ip link show ${vdev} 2>/dev/null >/dev/null; then
+ if link_exists "$vdev"; then
mac=`ip link show ${netdev} | grep 'link\/ether' | sed -e 's/.*ether \(..:..:..:..:..:..\).*/\1/'`
preiftransfer ${netdev}
transfer_addrs ${netdev} ${vdev}
if [ "${bridge}" == "null" ]; then
return
fi
- if ! ip link show ${bridge} >/dev/null 2>&1; then
+ if ! link_exists "$bridge"; then
return
fi
- if ip link show ${pdev} 2>/dev/null >/dev/null; then
+ if link_exists "$pdev"; then
ip link set dev ${vif0} down
mac=`ip link show ${netdev} | grep 'link\/ether' | sed -e 's/.*ether \(..:..:..:..:..:..\).*/\1/'`
transfer_addrs ${netdev} ${pdev}